class CreateAfterServices < ActiveRecord::Migration
  def self.up
    create_table :after_services do |t|
      t.integer :enterprise_id
      t.string :liable_side, :default => '厂家'
      t.string :installer_full_name
      t.integer :order_item_id
      t.integer :feed_id
      t.decimal :after_serviced_cost,:default => 0,
        :precision => 8, :scale => 2
      t.decimal :gathered_balance,
        :default => 0,
        :precision => 8, :scale => 2
      t.integer :updated_by_user_id
      t.date :after_serviced_on
      t.text :remark, :installed_remark
      t.timestamps
    end
    remove_column :installations,
                    :after_serviced_count,
                    :after_serviced_cost,
                    :after_serviced_remark
    add_column :installations,
                 :installed_cost,
                 :decimal, {:default => 0,
                 :precision => 8, :scale => 2}
    add_column :feeds,
                 :after_service_id,
                 :integer
  end

  def self.down
    drop_table :after_services
    add_column :installations, 
                 :after_serviced_count,
                 :integer, :default => 0
    add_column :installations,
                 :after_serviced_cost,
                 :decimal, :default => 0,
                 :precision => 8, :scale => 2
    add_column :installations, :after_serviced_remark, :text
    remove_column :installations,
                    :installed_cost
    remove_column :feeds,
                    :after_service_id
  end
end
